<?php
//xna Rss2.0
require_once('global.php');
if (!$options['rss_enable']) {
	exit('RSS Disabled');
}

$type = is_string($_GET[type]) ? $_GET[type]:"";
if (!empty($type)){
	$query = $db->query("SELECT cid,cate_title FROM {$tablepre}xna_category WHERE cate_title='" . $type . "'");
while ($row=$db->row($query)){
		$id = $row["cid"];
		$types = $row["site_title"];
	}
	if (eregi('^[a-zA-Z]+$', $type)){
		$arg = $type > "" ? " and x.rss_cate='$id' ":"";
	}
	else{
		$arg .= "";
	}
    $type = " for " . $type . "";
}

$str = '<?xml version="1.0" encoding="utf-8"?>
<!-- generator="www.ixna.net" -->
<rss version="2.0">
<channel>
	<title>'.$options[name].'' . $type . '</title>
	<description>XML News Aggregator</description>
	<link>http://www.ixna.net/</link>
	<language>zh-cn</language>
	<generator>iXNA.Net</generator>
	<webMaster>zxswww@gmail.com</webMaster>
	<ttl>'.$options['rss_ttl'].'</ttl>
	<image>
	<url>http://www.ixna.com/images/logo.gif</url>
	<link>http://www.ixna.net/</link>
	<title>iXNA.Net</title>
	</image>';
echo $str;

$query = $db->query("SELECT *  FROM {$tablepre}xna_feed WHERE state!='0' $arg order by state desc,addtime DESC LIMIT ".($options['rss_num'] ? intval($options['rss_num']) : 50));
while ($row=$db->row($query)){
    $row["rss_cate"] = $rss_cate[$row["rss_cate"]];
    $row["addtime"] = date("Y-m-d H:i:s",$row["addtime"]);
    if ( !$options['rss_all_output']) {
    	//$content = $row["feed_description"];
    	$content = $row['feed_description'].'<br /><br /><a href="'.$row['feed_url'].'" target="_blank">Read</a><br /><br />';
    }else{
    	$content = $row["feed_content"];
    	}
    $str = '<item>
		<title>' . $row["feed_title"] . '</title>
		<link>' . $row["feed_url"] . '</link>
		<author>' . $row["site_name"] . '</author>
		<pubDate>' . $row["addtime"] . '</pubDate>
		<description><![CDATA[' . $content. ']]></description>
		<category>' . $row["rss_cate"] . '</category>
	</item>';
    echo $str;
}
$str = '	</channel>
</rss>';
@header("Content-type:application/xml; charset=utf-8");
echo $str;
?>